package com.itany.book.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itany.book.book.service.IBookService;
import com.itany.book.pojo.Book;
import com.itany.book.vo.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2020/1/2 9:28
 * Describe:
 * version:1.0
 */

@RestController
@RequestMapping("/book")
public class BookController {

    @Reference
    private IBookService bookService;


    @RequestMapping("/findAllBooks")
    public ResponseResult findAllBooks(String lastType){
        System.out.println(lastType);
        List<Book> books = bookService.findAllBooks(lastType);
        return ResponseResult.success(books);
    }

    //从solr中搜索
    @RequestMapping("/findDoc")
    public ResponseResult findDoc(String keyword, @RequestParam(defaultValue = "1") Integer pageNum){
        int pageSize = 4;
        System.out.println(keyword);
        Map<String,Object> pageInfo = bookService.findDoc(keyword,pageNum,pageSize);
        // List<Book> books = bookService.findDoc(keyword);
        pageInfo.put("pageNum",pageNum);
        return ResponseResult.success(pageInfo);
        // return bookService.findDoc(keyword);
    }


    @RequestMapping("/findBookById")
    public ResponseResult findBookById(Integer id){
        Book book = bookService.findById(id);
        return ResponseResult.success(book);
    }
}
